package org.jash.sportnews2109.dao

import android.app.Application
import android.content.Context
import androidx.room.Room
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object DatabaseProvider {
    @Singleton
    @Provides
    fun getDatabase(@ApplicationContext app:Context) =
        Room.databaseBuilder(app, NewsDatabase::class.java, "news")
            .fallbackToDestructiveMigration()
            .build()
    @Singleton
    @Provides
    fun getNewsDao(newsDatabase: NewsDatabase) = newsDatabase.getNewsDao()
    @Singleton
    @Provides
    fun getUserDao(newsDatabase: NewsDatabase) = newsDatabase.getUserDao()
    @Singleton
    @Provides
    fun getVideoDao(newsDatabase: NewsDatabase) = newsDatabase.getVideoDao()
}